package com.shencai.saas.maintenance;

import com.shencai.fw.util.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 应用入口 spring boot start
 *
 * @author yxl
 */
@SpringBootApplication(scanBasePackages = "com.shencai")
@EnableTransactionManagement
@ServletComponentScan
@MapperScan("com.shencai.demo.base.mapper")
public class DemoBootApplication {
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(DemoBootApplication.class);
        initContextEnv(app);
        app.run(args);
    }

    private static void initContextEnv(SpringApplication app) {
        Properties props = System.getProperties();
        Map<String, Object> contextMap = new HashMap<>(3);
        contextMap.put("server.port", StringUtils.checkNullOrEmpty(props.getProperty("port"), "18080"));
        contextMap.put("server.servlet.context-path", "/".concat(StringUtils.checkNullOrEmpty(props.getProperty("contextPath"), "demo")));
        contextMap.put("configFileName", "appSettings.properties");
        app.setDefaultProperties(contextMap);
    }
}
